<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
   <base href="<%=basePath%>">
   
   <title>My QRcode</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<%=request.getContextPath() %>/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/jquery.qrcode.min.js"></script>
 </head>

<body>
	生成二维码如下:
	<br/>
	<div id="qrcode"></div>
	<script type="text/javascript">
		var str = "https://www.baidu.com/ 百度一下,你就知道";
		/* jQuery('#qrcode').qrcode(utf16to8(str)); */
		jQuery('#qrcode').qrcode({
			render : "table", //渲染模式,table兼容ie,canvas性能好
			text : utf16to8(str), //内容
			width : "200", //宽
			height : "200", //高
			correctLevel : 2, //纠错等级LMQH(1234)
			background : "#ffffff", //背景色一般为白色
			foreground : "#000000", //前景色一般为黑色
		});
		//utf-16转utf-8
		function utf16to8(str) {
			var out, i, len, c;
			out = "";
			len = str.length;
			for (i = 0; i < len; i++) {
				c = str.charCodeAt(i);
				if ((c >= 0x0001) && (c <= 0x007F)) {
					out += str.charAt(i);
				} else if (c > 0x07FF) {
					out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
					out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
					out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
				} else {
					out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
					out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
				}
			}
			return out;
		}
	</script>
</body>
</html>
